package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.po.AreaPo;
import com.bodu.system.entity.request.AreaRequest;
import com.bodu.system.entity.vo.AreaVo;
import com.bodu.system.service.AreaService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Administrator
 */
@Api(tags = "区域管理")
@RestController
@RequestMapping("/area")
public class AreaController extends AbstractCommonController<AreaService, AreaRequest, AreaVo> {

    public AreaService areaService;

    public AreaController(AreaService areaService) {
        this.areaService = areaService;
    }

    /**
     * 根据parentCode查询单位数据
     *
     * @param parentCode 父类编号
     * @return 子类地区集合
     */
    @TraceLog()
    @GetMapping("findAreaByParentCode/{parentCode}")
    public Result findAreaByParentCode(@PathVariable("parentCode") Long parentCode) {
        List<AreaPo> areaPos = areaService.findAreaByParentCode(parentCode);
        return Result.success(areaPos);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
